unit PlugInTestOne;

interface

uses
  Windows, Messages, SysUtils, Classes, Dialogs, Forms,

  JvPlugin, JvPlgIntf, RzTabs, Graphics;

type
  TTestOne = class(TJvPlugIn, IMyPluginInterface)
    procedure JvPlugInInitialize(Sender: TObject; var AllowLoad: Boolean);
    procedure JvPlugInDestroy(Sender: TObject);
    procedure JvPlugInCreate(Sender: TObject);
  private

  protected
    OldApplication: TApplication;
    OldScreen: TScreen;
    FMainApp: IMyMainAppInterface;
  public

    procedure ShowPlug(Sender: TObject);
    function CloseForm(Sender: TObject): Boolean;

    procedure ShowPlugName(Sender: TObject; FormName: string);
    function GetForm(Sender: TObject; FormName: string): TForm;

    procedure Init(const MainApp: IMyMainAppInterface; HostScreen: TScreen);

    function GetClassForm(FormName: string): TFormClass;
    procedure GetShowModal(FormName:string);

    function GetFormNum:Integer;
  end;

function RegisterPlugin: TJvPlugIn; stdcall;

implementation

{$R *.dfm}

// IMPORTANT NOTE: If you change the name of the Plugin container,
// you must set the type below to the same type. (Delphi changes
// the declaration, but not the procedure itself. Both the return
// type and the type created must be the same as the declared type above.
uses FormParent, TestOneOne, TestOneTwo,TestShowModal, One,VariableCommon;

function RegisterPlugin: TJvPlugIn;
begin
  Result := TTestOne.Create(nil);
end;

procedure TTestOne.JvPlugInInitialize(Sender: TObject; var AllowLoad: Boolean);
begin
  OldApplication := Application;
  Application.Handle := HostApplication.Handle;
end;

procedure TTestOne.Init(const MainApp: IMyMainAppInterface;
  HostScreen: TScreen);
begin
  FMainApp := MainApp;
  OldScreen := Screen;
  Screen := HostScreen;
end;

procedure TTestOne.JvPlugInCreate(Sender: TObject);
begin
  RegisterClasses([TfrmTestOneOne, TfrmTestOneTwo,TfrmTestShowModal]);
end;

procedure TTestOne.JvPlugInDestroy(Sender: TObject);
begin
  Application.Handle := OldApplication.Handle;
  Screen := OldScreen;
end;

function TTestOne.GetClassForm(FormName: string): TFormClass;
begin
  Result := TFormClass(GetClass('T' + FormName));
end;

procedure TTestOne.GetShowModal(FormName: string);
begin
//TForm(TFormClass(GetClass('T' + FormName))).Create(Application)
   with TfrmTestShowModal.Create(Application) do
   begin
     ShowModal;
     Free;
   end;
end;



function TTestOne.GetForm(Sender: TObject; FormName: string): TForm;
var
  TheClass: TPersistentClass;
begin
  TheClass := GetClass('T' + FormName);
  if (TheClass = nil) then
    exit;
  if TheClass.InheritsFrom(TForm) then
  begin
    Result := TForm(TheClass.Create).Create(Application);
    try
    finally
    end;
  end;
end;

function TTestOne.GetFormNum: Integer;
begin
   Result:=formNum;
end;

function TTestOne.CloseForm(Sender: TObject): Boolean;
begin
  if frmTestOneOne <> nil then
  begin
    frmTestOneOne.Close;
  end;
end;

procedure TTestOne.ShowPlug(Sender: TObject);
begin
  if frmTestOneOne = nil then
  begin
    frmTestOneOne := TfrmTestOneOne.Create(nil); // Application
    // frmTestOneOne.MainApp := FMainApp;
  end;

  frmTestOneOne.Show;
end;

procedure TTestOne.ShowPlugName(Sender: TObject; FormName: string);
var
  TheClass: TPersistentClass;
  aForm: TForm;
begin
  TheClass := GetClass('T' + FormName);
  if (TheClass = nil) then
    exit;
  if TheClass.InheritsFrom(TForm) then
  begin
    aForm := TForm(TheClass.Create).Create(Application);
    try
      aForm.Show;
    finally
    end;
  end;
end;

end.
